<template>
  <div>
    <el-dialog :visible.sync="dialogVisible" v-if="dialogVisible" width="60%">
      <el-form :model="formData" :rules="rules" ref="dataFrom" label-width="150px">
        <!--        <el-form-item label="商品id" prop="id">-->
        <!--          <el-input placeholder="如需要更新数据请输入对应id，如需新增数据则不输入此项" v-model="formData.id"></el-input>-->
        <!--        </el-form-item>-->
        <el-form-item label="用户名" prop="username">
          <el-input v-model="formData.username"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名" prop="realname">
          <el-input v-model="formData.realname"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="formData.password"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="telephone">
          <el-input v-model="formData.telephone"></el-input>
        </el-form-item>
        <el-form-item label="微信" prop="wxid">
          <el-input v-model="formData.wxid"></el-input>
        </el-form-item>
        <el-form-item label="QQ" prop="qq">
          <el-input v-model="formData.qq"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="formData.gender"></el-input>
        </el-form-item>
        <el-form-item label="照片" prop="photo">
          <!--          <el-input v-model="formData.photo"></el-input>-->
          <el-upload
              class="upload-demo"
              action=""
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :limit="1"
              :on-exceed="handleExceed"
              :http-request="appendFile"
              :file-list="fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
          </el-upload>

        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-input v-model="formData.province"></el-input>
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="formData.city"></el-input>
        </el-form-item>
        <el-form-item label="区域" prop="area">
          <el-input v-model="formData.area"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="uploadData">立即上传</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {uuid as $uuid} from "vue-uuid";

export default {
  name: "addcustomer",
  data() {
    return{
      formData:{
        "id": "",
        "username": "",
        "realname": "",
        "password": "",
        "enabled": "",
        "type": "",
        "telephone": "",
        "qq": "",
        "wxid": "",
        "registerTime": "",
        "lastLoginTime": "",
        "lastLoginIp": "",
        "registerIp": "",
        "gender": "",
        "status": "",
        "idCard": "",
        "idcardPhotoPositive": "",
        "idcardPhotoNegative": "",
        "bankCard": "",
        "bankCardPhoto": "",
        "forbiddenReason": "",
        "province": "",
        "city": "",
        "area": "",
        "rank": "",
        "comment": ""
      },
      rules:{
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
        ],
      },
      dialogVisible: false,
      infoData:[],
      showAll:false
    }
  },
  methods:{
    uploadData(){
      this.$refs.dataFrom.validate((valid) => {
        if (valid) {
          let that=this;
          let url=that.$URL.addcustomer;
          let uuid = $uuid.v1()
          let idd = uuid
          console.log(that.formData.id)
          if (that.formData.id == ""){
            idd = uuid
            console.log(idd)
          }
          else {
            idd = that.formData.id
            console.log(idd)

          }
          let uploadcustomerParams = {
            id:"",
            username:that.formData.username,
            realname:that.formData.realname,
            password:that.formData.password,
            type:"customer",
            qq:that.formData.qq,
            wxid:that.formData.wxid,
            registerTime:that.formData.registerTime,
            lastLoginTime:that.formData.lastLoginTime,
            lastLoginIp:that.formData.lastLoginIp,
            registerIp:that.formData.registerIp,
            gender:that.formData.gender,
            status:that.formData.status,
            idCard:that.formData.idCard,
            idcardPhotoPositive:that.formData.idcardPhotoPositive,
            idcardPhotoNegative:that.formData.idcardPhotoNegative,
            bankCard:that.formData.bankCard,
            bankCardPhoto:that.formData.bankCardPhoto,
            forbiddenReason:that.formData.forbiddenReason,
            province:that.formData.province,
            city:that.formData.city,
            area:that.formData.area,
            rank:that.formData.rank,
            comment:that.formData.comment
          };
          console.log(uploadcustomerParams)
          that.$axios.post(url, uploadcustomerParams).then(
              res => {
                if (res.status == 200) {
                  that.$message({
                    message: "上传成功"+res.data,

                    type: 'success'
                  });
                  that.$refs.formData.resetFields();
                } else {
                  that.$message({
                    message: "上传失败",
                    type: 'error'
                  });
                }
              }
          );
        }
      });
    }
  },
  created() {
    let that=this;
    this.$Bus.$on('addcustomer',param=>{
      that.dialogVisible=param.dialogVisible
      that.infoData=param.infoData
      that.showAll=false
    })
  }
}
</script>

<style scoped>

</style>
